﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Dycox.Reporting
{
    public abstract class ReportElement : IHasStyle
    {
        public ReportElement()
        {

        }

        private ContainerElement _parent;

        public ContainerElement Parent
        {
            get { return _parent; }
            internal set
            {
                if (_parent != value)
                {
                    OnParentChanging(value);
                    _parent = value;
                }
            }
        }

        protected virtual void OnParentChanging(ReportElement parent)
        {
        }

        public virtual Report Report
        {
            get
            {
                if (_parent == null)
                    return null;
                else
                    return _parent.Report;
            }
        }

        private ElementStyle _style;

        public ElementStyle Style
        {
            get
            {
                if (_style == null)
                    _style = new ElementStyle();

                return _style;
            }
        }

        public ElementStyle GetRuntimeStyle()
        {
            ElementStyle style = new ElementStyle();
            ElementStyle other;
            ReportElement elt = this;

            while (elt != null)
            {
                other = elt._style;
                if (other != null)
                    style.OverrideBy(other);

                elt = elt.Parent;
            }

            style.OverrideBy(Report.DefaultStyle);

            return style;
        }


        //protected internal abstract RectangleF GetBounds(ReportRenderer renderer);

        protected internal abstract void Render(RenderingContext context);

        protected internal abstract RectangleF GetBounds(RenderingContext context);

    }
}
